<template>
  <div id="student">
    <el-row type="flex" class="" justify="center">
      <el-col :span="23" class="line">
        <i class="el-icon-menu"></i>学生信息
      </el-col>
    </el-row>
    <div class="content" v-loading.fullscreen.lock="fullscreenLoading"
              element-loading-text="拼命加载中"
    element-loading-spinner="el-icon-loading"
    element-loading-background="rgba(0, 0, 0, 0.2)">
     <div style="text-align:left;margin-bottom:20px;">
          <el-select placeholder="全部状态" v-model="status" @change="selectChange">
            <el-option label="未评审" value=1></el-option>
            <el-option label="未提交" value=2></el-option>
            <el-option label="已提交" value=3></el-option>
          </el-select>
          <el-button type="primary" plain style="float:right;margin-left:5px;" @click="submit()">一键上传</el-button>
          <el-button type="primary" plain style="float:right;" @click="download()">打印凭证</el-button>
      </div>
      <el-card class="box-card">
        <el-table
          :data="tableData"
          stripe
          style="width: 100%">
          <el-table-column
            prop="ticket"
            label="记录号"
            align="center">
          </el-table-column>
          <el-table-column
            prop="name"
            label="姓名"
            align="center">
          </el-table-column>
          <el-table-column
            prop="create_time"
            label="报名时间"
            align="center">
          </el-table-column>
          <el-table-column
            prop="state"
            label="状态"
            align="center">
          </el-table-column>
          <el-table-column
            label="操作"
            align="center">
            <template slot-scope="scope">
               <el-button type="primary" size="mini" @click="gotoDetail(scope.row)">查看详情</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="pages">
            <el-pagination
              background
              @current-change="handleCurrentChange"
              :page-size="pageSize"
              layout="prev, pager, next, jumper"
              :total="total">
            </el-pagination>
          </div>
      </el-card>
     </div>
  </div>
</template>

<script>
  import VDistpicker from 'v-distpicker'
  export default {

    data() {
      return {
        status:'',
        fullscreenLoading:false,
        tableData: [{
          ticket:'11',
          name:'张三',
          create_time:'2018-01-23',
          state:'未评审'
        }],
        total:0,
        pageSize:10,  
      }
    },
    components: {
      VDistpicker
    },
    mounted(){
      this.getAllStudent();
    },
    methods: {
      getInfo(){
        var that=this;
        // this.axios({
        //   url:this.host+'/3v1t.smserver.cn/index.php/index/student.Progress/all_entry',
        //   method:'post',
        //   headers:{
        //         "Content-type":"application/json"
        //   }
        // }).then((res)=>{
        //   console.log(res);
        //   that.fullscreenLoading=false;
          
        // })
      },
      gotoDetail(mess){
        this.$router.push({
            path: '/reviewerHome/stuMessage',
            query: { id: mess.userId}
            /*query: {
                name: 'name', 
                dataObj: this.msg
            }*/
        })
        //this.$router.push('/userHome/progressDetail')
      },
      getStudent(mess){
        var that=this;
        this.fullscreenLoading=true;
        this.axios({
            url:this.host+'/3v1t.smserver.cn/index.php/audit/index/index',
            method:'post',
            data:JSON.stringify(mess),
            headers:{
                  "Content-type":"application/json"
                }
          }).then((res)=>{
            console.log(res);
            this.fullscreenLoading=false;
            var data=res.data.data;
            that.total=data.count;
            var arr=[];
            data.data.forEach((item)=>{
              if(item.status==1){
                item.state="未评审";
              }else if(item.status==2){
                item.state="未提交";
              }else{
                item.state="已提交";
              }
              item.entry.update_time=item.entry.update_time.split(" ")[0];
              arr.push({
                ticket:item.entry.ticket,
                name:item.userbase.name,
                create_time:item.entry.update_time,
                state:item.state,
                userId:item.id
              })
            })
            that.tableData=arr;
          })    
      },
      getAllStudent(){
        var message={
          page:1,
          num:this.pageSize,
          status:""
        }
        this.getStudent(message)
      },
      handleCurrentChange(val) {
        console.log(val)
        var message={
            page:val,
            num:this.pageSize
        }
        this.getStudent(message);
      },
      selectChange(val){
        var message={
          page:1,
          num:this.pageSize,
          status:val
        }
        this.getStudent(message)
      },
      submit(){
          var that=this;
          var message={
            id:this.userId
          }
          this.$confirm('提交后将无法修改评审结果,请先保存修改结果?', '提示', {
            confirmButtonText: '已保存,提交',
            cancelButtonText: '去保存',
            type: 'warning'
          }).then(() => {
              this.axios({
                url:this.host+'/3v1t.smserver.cn/index.php/audit/index/download_post',
                method:'post',
                data:JSON.stringify(message),
                headers:{
                      "Content-type":"application/json"
                }
              }).then((res)=>{
                if(res.data.code==1){
                        that.fullscreenLoading=false;
                        that.$message({
                          type:'success',
                          message:''+res.data.msg
                        })
                      }else if(res.data.code==2){
                         that.fullscreenLoading=false;
                        that.$message({
                          type:'warning',
                          message:''+res.data.msg
                        })
                      } 
                that.fullscreenLoading=false;
              })
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消提交'
            });          
          });       
      },
      download(){
        window.open(this.host+"/3v1t.smserver.cn/index.php/audit/index/download")
      }
    }
  }

</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss">
  #student {
    //width:100%;
    //line-height:100%;
    padding: 10px;
    .line {
      border-bottom: 1px solid #ccc;
      text-align: left;
      height: 50px;
      line-height: 50px;
      padding-left: 10px;
    }
    .content {
      padding: 20px;
      text-align: center;
    }
    .download{
      float:right;
      width:130px;
      margin:0 20px;
    }
    .pages{
      text-align:center;
      margin:20px 0;
    }
    
  }

</style>
